package com.geekaca.d07.test_stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class StreamTest2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        list.add("张无忌");
        list.add("周芷若");
        list.add("赵敏");
        list.add("张强");
        list.add("张三丰");
        list.add("张三丰");

        list.stream().filter(s->s.startsWith("张")).forEach(s-> System.out.println(s));
        System.out.println("==============");
        list.stream().filter(s->s.startsWith("张")).limit(2).forEach(System.out::println);
        System.out.println("==============");
        list.stream().filter(s->s.startsWith("张")).skip(2).forEach(System.out::println);
        System.out.println("+++++++++++++");
        long count = list.stream().filter(s -> s.length() == 3).count();
        System.out.println(count);

        // 对元素进行加工
        list.stream().map(s->"极客咖"+s).forEach(System.out::println);
        System.out.println("====================");
        //遍历集合,利用名字逐一构造学生对象
        list.stream().map(s->new Student(s)).forEach(stu-> System.out.println(stu));

        // 流的合并
        Stream<String> zhangstream = list.stream().filter(s -> s.startsWith("张"));
        Stream<String> java = Stream.of("java", "Cpp");
        Stream<String> concat = Stream.concat(zhangstream, java);

//        System.out.println(concat.toList());
        System.out.println("==============" );
//        concat.forEach(System.out::println);
        System.out.println("=============");
        concat.distinct().forEach(System.out::println);

    }
}
